# -*- coding: utf-8 -*-
import scrapy
from scra_project.items import DmozItem


class DmozSpider(scrapy.Spider):
    name = "Dmoz"
    allowed_domains = ["dmoz.org"]
    start_urls = [
        'http://www.dmoz.org/Computers/Programming/Languages/Python/Books/'
    ]

    def parse(self, response):
        bookItem = response.selector.css('.title-and-desc')
        for sel in bookItem:
            item = DmozItem()
            item['title'] = sel.xpath('a/div/text()').extract_first()
            item['link'] = sel.xpath('a/@href').extract_first()
            item['desc'] = sel.css('.site-descr::text').extract_first().strip()
            print("Title: {}\nLink: {}\nDesc: {}\n\n".format(item['title'],item['link'],item['desc']))
            yield item
